CBetterPopupMenu is a canvas-based custom class for REALbasic 2.1 or higher. It gives you a popupmenu control that can have two appearances; the white system7-styled one, and a nice bevelled one. There have been some classes that do this before, but they have required expensive third-party plugins. CBetterPopupMenu is 100% REALbasic code. No plugins are used.
This class is free. However, if you use it, give me credit (that is, mention me in the about box).
V e r s i o n H i s t o r y
• Version 1.1 added the ability to specify the TextFont and TextSize of the control.
• Version 1.2 fixed a bug that caused the menubar to go mad when the control used another font than System 12.
• Version 1.5 fixed a bug causing empty controls to crash, removed the need to manually set the MenuID property, and added support for the standrad MacOS popupmenu look.
H o w T o U s e
Important - In CBetterPopupMenu 1.5, you no longer need to set the menu id manually - this is handled automatically by the control.
To decide which appearance the control should have, set the Style property in the Open event. A value of 0 (default) gives a bevel style popupmenu, and the value 1 gives a System 7 (b/w) one. The value 2 gives a control looking very similar to the default popup menu.
A d d i n g & D e l e t i n g R o w s
These are the methods and functions you use to add and delete rows to the PopupMenu.
AddRow(text as string)
adds a row to the popupmenu.
InsertRow(position as integer, text as string)
inserts a row after the row specified by the position parameter.
RemoveRow(n as integer)
removes the row specified by the n parameter.
DeleteAllRows()
deletes all rows from the menu.
AddSeparator()
adds a separator line to the menu.
ListCount() as integer
returns the number of rows in the menu.
ListIndex() as integer
returns the number of the currently selected item.
M a n i p u l a t i n g R o w T e x t
These are the methods and functions you use to get and set the text of the rows in the popupmenu.
List(n as integer) as string
returns the text of row number n.
SetList(n as integer, text as string)
sets the text of row number n to text.
Text() as string
returns the text of the currently selected item.
SetText(text as string)
sets the text of the currently selected item.
E n a b l i n g & D i s a b l i n g R o w s
These are the methods and functions you use to Enable and Disable rows in the menu.
EnableRow(row as integer)
enables the row specified by the row parameter.
DisableRow(row as integer)
disables the row specified by the row parameter.
M a n i p u l a t i n g R o w S t y l e
These are the methods and functions you use to change the style of the rows in the menu.
SetRowBold(row as integer, on as boolean)
if the on parameter is true, this method applies bold style to the row specified, else it removes eventual boldness.
SetRowItalic(row as integer, on as boolean)
if the on parameter is true, this method applies italic style to the row specified, else it removes eventual italicness.
SetRowUnderline(row as integer, on as boolean)
if the on parameter is true, this method applies underline style to the row specified, else it removes eventual underlinity.
RowBold(row as integer) as boolean
returns true if the row specified has a bold style.
RowItalic(row as integer) as boolean
returns true if the row specified has an italic style.
RowUnderline(row as integer) as boolean
returns true if the row specified has an underlined style.
M a n i p u l a t i n g I c o n s & C h e c k m a r k s
These are the methods and functions you use to set the icon of menu rows, and to set checkmarks in the menu.
CheckRow(row as integer, checked as boolean)
if the checked property is true, this method checks the row specified, else it unchecks it.
SetRowIcon(row as integer, cicn_ID as integer)
puts a color icon ("cicn") in the row specified. The cicn_ID parameter must contain the ID of a "cicn" resource in the application resource fork. Also, the id of the resource must be over 256.